//
//  SFAudioPlayer.h
//  Test
//
//  Created by xueshan1 on 2018/11/13.
//  Copyright © 2018年 xueshan1. All rights reserved.
//
//     NSString *audioUrl1 = @"http://download.lingyongqian.cn/music/ForElise.mp3";

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
 #define kWeakSelf __weak __typeof(&*self)weakSelf = self;


typedef NS_ENUM(NSUInteger, SFAudioPlayerSessionCategory) {
    SFAudioPlayerSessionCategory_Ambient,    //用于播放,随用户锁屏和静音而静音,不终止其他播放声音
    SFAudioPlayerSessionCategory_SoloAmbient,//用于播放,随用户锁屏和静音而静音,终止其他播放声音
    SFAudioPlayerSessionCategory_Playback,   //用于播放,不随用户锁屏和静音而静音,终止其他播放声音(需设置后台播放background mode)
};
typedef NS_ENUM(NSUInteger,SFAudioPlayerState){
    SFAudioPlayerState_Stopped =100,
    SFAudioPlayerState_ReadyPlay,
    SFAudioPlayerState_Playing,
    SFAudioPlayerState_Pause,
    SFAudioPlayerState_Failed,
    SFAudioPlayerState_Buffering
    
};

@class SFAudioPlayer;
@protocol ISFAudioPlayerDelegate <NSObject>

//播放进度
- (void)sf_player:(SFAudioPlayer *)player progress:(CGFloat)progress currentTime:(CGFloat)currentTime totalTime:(CGFloat)totalTime;

//缓冲进度
- (void)sf_player:(SFAudioPlayer *)player bufferProgress:(CGFloat)bufferProgress totalTime:(CGFloat)totalTime;

//播放结束
- (void)sf_playerDidPlayToEndTime:(SFAudioPlayer *)player;

//播放失败
- (void)sf_playerPlayFailed:(NSString *)errMsg;

//播放状态
- (void)sf_playerPlayState:(SFAudioPlayerState)playState;

@end

 
@interface SFAudioPlayer : NSObject

#pragma mark --状态
//播放器状态
@property(nonatomic,readonly,assign)SFAudioPlayerState playState;
//播放进度
@property(nonatomic,assign)CGFloat sf_progress;
//进度变化回调
@property(nonatomic,copy)void(^progressChangeBlock)(CGFloat sf_progress);
//当前播放时长
@property(nonatomic,assign)CGFloat sf_currentTime;
//总时长
@property(nonatomic,assign)CGFloat sf_totalTime;
//缓冲进度
@property(nonatomic,assign)CGFloat sf_bufferProgress;
/**远程控制*/
@property(nonatomic,assign)BOOL receiveRemoteControl;

#pragma mark --控制
//播放类别
@property(nonatomic,assign)SFAudioPlayerSessionCategory sessionCategory;
//是否循环播放 default NO
@property(nonatomic,assign)BOOL isRecyclePlay;
//播放速度
@property(nonatomic,assign)CGFloat sf_rate;
//设置播放进度 0~1
@property(nonatomic,assign)CGFloat progressValus;
//自定义缓存default NO (系统将不会自动加载)
@property(nonatomic,assign)BOOL needCustomeCache;




@property(nonatomic,weak)id<ISFAudioPlayerDelegate>delegate;

+ (instancetype)shareInstance;
//初始化
- (void)initPlayer;
//播放一个音频
- (void)sf_playAudioWithURL:(NSURL *)audioURL  isLocalFile:(BOOL)isLocal;
- (void)sf_playAudioWithURLString:(NSString *)audioURLString  isLocalFile:(BOOL)isLocal;

//播放(第一次播放不需要调用)
- (void)sf_audioPlay;
//暂停
- (void)sf_audioPause;
//释放播放器
- (void)sf_deallocPlayer;

- (void)seeKToZeroAndPause;

@end


